package com.jeejam.product.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.jeejam.framework.base.pojo.Pager;
import com.jeejam.product.pojo.ProductType;
import com.jeejam.product.sdk.api.IProductTypeService;
import com.jeejam.product.sdk.dto.ProductTypeDto;
import com.jeejam.product.service.ProductTypeService;
import com.jeejam.util.ShopBeanBuildUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by JACKEY on 2016/3/18.
 */
@Service(version = "1.0.0")
public class ProductTypeDubboService implements IProductTypeService {

    @Resource
    private ProductTypeService productTypeService;

    @Override
    public int counts() {
        return productTypeService.counts();
    }

    @Override
    public Pager getPager(int currentPage, int pageSize) {
        return productTypeService.getPager(currentPage, pageSize);
    }

    @Override
    public List<ProductTypeDto> findAllByPage(int currentPage, int pageSize) {
        List<ProductType> productTypeList = productTypeService.selectAllByPage(currentPage, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(productTypeList, ProductTypeDto.class);
    }

    @Override
    public List<ProductTypeDto> findAll() {
        List<ProductType> productTypeList = productTypeService.findAll();
        return ShopBeanBuildUtil.slmCopyBeanList(productTypeList, ProductTypeDto.class);
    }

    @Override
    public Pager getPagerByCounts(int counts, int currentPage, int pageSize) {
        return productTypeService.getPagerByCounts(counts, currentPage, pageSize);
    }

    @Override
    public void deleteById(int id) {
        productTypeService.deleteById(id);
    }

    @Override
    public ProductTypeDto getById(int id) {
        ProductType productType = productTypeService.findById(id);
        return ShopBeanBuildUtil.slmCopyBean(productType, ProductTypeDto.class);
    }

    @Override
    public void save(ProductTypeDto productTypeDto) {
        ProductType productType = ShopBeanBuildUtil.slmCopyBean(productTypeDto, ProductType.class);
        productTypeService.save(productType);
    }

    @Override
    public void update(ProductTypeDto productTypeDto) {
        ProductType productType = ShopBeanBuildUtil.slmCopyBean(productTypeDto, ProductType.class);
        productTypeService.save(productType);
    }

    @Override
    public int getTotalPage(int counts, int pageSize) {
        return productTypeService.getTotalPage(counts, pageSize);
    }
}
